<template>
  <div>
    <el-card>
      <div slot="header" class="clearfix text-left">
        <el-col :span="23">
          <span class="title-icon">DHL追踪号</span>
        </el-col>
      </div>

      <el-form
        ref="ruleForm"
        :rules="rules"
        label-position="left"
        label-width="100px"
        :model="form"
      >
        <el-form-item label="运单号" prop="waybillNos">
          <el-input
            type="textarea"
            v-model="form.waybillNos"
            :rows="5"
            placeholder="请输入运单号(德国),多个换行隔开"
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="trackPrintlabelDhl"
            >获取DHL追踪号</el-button
          >
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
import { ajax } from "@/store/yg/common/utils";
import axios from "axios";
import * as constant from "@/store/yg/common/constant";
import { Toast } from "mint-ui";

export default {
  components: {},
  props: [],
  data() {
    return {
      form: {
        waybillNos: ""
      },
      rules: {
        waybillNos: [
          { required: true, message: "请输入运单号", trigger: "blur" }
        ]
      }
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    // trackPrintlabelDhl() {
    //   if (!this.waybillNos) {
    //     this.$message.error("请输入运单号");
    //   }
    //   ajax("trackPrintlabelDhl", { waybillNos: this.waybillNos }).then(
    //     res => {
    //       console.log(res);
    //       if (res.code == 200) {
    //         this.$message.success("成功");
    //       } else {
    //         this.$message.error(res.data);
    //       }
    //     },
    //     error => {
    //       console.log(error);
    //     }
    //   );
    // },
    trackPrintlabelDhl() {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          this.saveData();
        } else {
          return false;
        }
      });
    },
    saveData() {
      ajax(
        "trackPrintlabelDhl",
        {
          waybillNos: this.form.waybillNos
        },
        { type: "mobile" }
      )
        .then(res => {
          console.log(res);
          if (res.code == 200) {
            this.waybillNos = null;
            Toast({
              message: "获取成功",
              iconClass: "icon icon-success"
            });
          } else {
            Toast("获取失败，" + res.data);
          }
        })
        .catch(error => {
          console.log(error);
          Toast("获取失败，" + error);
        });
    }
  }
};
</script>
<style></style>
